package com.itholmes.session;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.Cookie;

public class HttpSessionImpl implements HttpSession{
	
	//JSESSIONID
	private String JSESSIONID;
	
	//session的attribute
	private Map<String,Object> attribute = new HashMap<String,Object>();
	
	//超时时长
	private int interval;
	
	public String getJSESSIONID() {
		return JSESSIONID;
	}

	public void setJSESSIONID(String JSESSIONID) {
		this.JSESSIONID = JSESSIONID;
	}

	public int getInterval() {
		return interval;
	}

	public void setInterval(int interval) {
		this.interval = interval;
	}

	@Override
	public String getId() {
		return getJSESSIONID();
	}

	@Override
	public Object getAttribute(String name) {
		return attribute.get(name);
	}

	@Override
	public void setAttribute(String name, Object object) {
		attribute.put(name, object);
	}

	@Override
	public void removeAttribute(String name) {
		attribute.remove(name);
	}

	@Override
	public void setMaxInactiveInterval(int interval) {
		setInterval(interval);
	}

	@Override
	public int getMaxInactiveInterval() {
		return getInterval();
	}

	//用户第一次进入创建JSESSIONID
	public void createJsessionId() {
		UUID uuid = UUID.randomUUID();
		setJSESSIONID(uuid.toString());
	}

	//检查请求头是否有Cookie: JSESSIONID=BD0F4413B32F0172CEF2AAC8390E8FA6
	public void checkCookie() {
		
	}
}
